<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
require_once("../Scripts/authenticate.php"); //Only users who are logged in can access this page
require_once("../Scripts/DatabaseConnect.php");
require_once("../Scripts/UpdateStocks.php");//Checks if we need to update the database with new market data.

//Check if we need local server or remote server
$con=Remoteconnect();
if($con==null){
	$con=Localconnect();	
}
//Display the last update date and current date and time.
$lastUpdate="";
$result = mysqli_query($con,"SELECT * FROM  `time`");

while($row = mysqli_fetch_array($result)) {
	$lastUpdate=$row['LastUpdate'];

  
}

$date = date('m-d-Y h:i:s a', time());//gets current date and time of server.
echo"Date: $date, Last Update: $lastUpdate";?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<title>J&J Free Stock backtesting</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no" />
<link rel="stylesheet" href="businesstoday/styles/layout.css" type="text/css" />
</head>
<body id="top">
<div class="wrapper col1">
  <div id="header">
    <img src="../Images/the-top-5-high-volume-trading-stocks-of-the-week_1118_437849_0_14042581_500.jpg" alt="" width="240" height="162" />
    <div id="logo">
      <h1>J&amp;J Free Stock Backtesting    </h1>
    </div>
     <div id="newsletter">
    <div id="login" style="display:block; min-height:50px; min-width:600px;">
      <p><a href="#">Lost your password?</a> <a href="register.php">Register</a>

      </p>
      
      <form action="../Scripts/authenticate.php" method="post" >
      
        <fieldset>
          <legend>NewsLetter</legend>
          <table>
            <tr>
              <td>Name:</td>
              <td><input type="email" name="email" required="required" id="email" /></td>
              <td>Password:</td>
              <td><input type="password" name="password" required="required" id="password" /></td>
              <td><input type="submit" name="news_go" id="news_go" value="Login" /></td>
            </tr>
          </table>
        </fieldset>
      </form>


      </div>
      
      <?php
	  //Wrong password message
      if (isset($_SESSION['msg'])) {
	echo "<p style='color:red'>".$_SESSION['msg']."</p>"; 
	//remove the message since it has been displayed.
	unset($_SESSION['msg']);
	}
	?>
    
   	<?php
	//logout button
    if (isset($_SESSION['msgG'])) {
		echo"<form>";
		echo "<p style='color:green'>".$_SESSION['msgG']."</p>"; 
		echo '<input type="button" name="logout" id="logout" value="Logout" onClick="location.href=\'../Scripts/Logout.php\'"/>'; 
		echo"</form>";
	}
	
?> 
  

    </div>
    <br class="clear" />
  </div>
</div>

<div class="wrapper col2">
  <div id="topbar">
    <div id="topnav">
      <ul>
        <li class="active">
         
              <li><a href="index.php">Home Page</a></li>
              <li id="portfolio" style="display:none"><a href="portfolio.php">Stock Portfolio</a></li>
              <li id="stockMonitoring" style="display:none"><a href="stockMonitoring.php">Stock Monitoring</a></li>
              <li><a href="stockbacktest.php">Stock Backtest</a></li>
              <li><a href="charts.php">Stock Charts</a>
               <ul>
            <li><a href="chartDifShares.php">Stock Prices Comparision Chart</a></li>
            <li><a href="chartIndicators.php">Stock Technical Analysis Chart</a></li>
         
          </ul>
        </li>

        
  </li>      
        
        
      </ul>
    </div>
 <script type="text/javascript">
  //Hides/Shows navigation bar links based on logged in status
	  var check = <?php echo json_encode(isset($_SESSION['email'])); ?>;
	  
	  if(check==true){
		  document.getElementById("login").style.display="none";
		  document.getElementById("portfolio").style.display="block";
		  document.getElementById("stockMonitoring").style.display="block";

	  }else{
		  document.getElementById("login").style.display="block";
		  document.getElementById("stockMonitoring").style.display="none";
		  document.getElementById("portfolio").style.display="none";
		  
	  }
	 
 </script>
 
       
    <br class="clear" />
  </div>
</div>
<div class="wrapper col3">  <div id="intro">
    <div class="fl_right"></div>
          <p><a href="PortfolioStats.php">Portfolio Stats</a> &nbsp;&nbsp;&nbsp;  <a href="PortfolioTrans.php">Transaction Data</a>&nbsp;&nbsp;&nbsp; <a href="EditData.php">Edit Transaction Data</a></p>
<br class="clear" />
  </div>
</div>
<div class="wrapper col4"></div>
<div class="wrapper col5">
  <div id="container">
    <div id="content" style=" max-height:900px; overflow:auto">
      <h2>Edit TransactionData</h2>
       <?php
			  	
    

			  	$con=Remoteconnect();
				if($con==null){					
					$con=Localconnect();						
				}
				$result = mysqli_query($con,"SELECT * FROM `userportfolio` WHERE Email ='".$_SESSION['email']."'");


				

				while($row = mysqli_fetch_array($result)) {
					
    		?>              
            <form id="Add to portfolio" name="addPortfolio" method="post" action="../Scripts/EditPortfolioProcess.php">
         
            
            
     		<?php
			//Use this form for stock transactions:
			if($row['Symbol']!=""){
				echo"<strong>".$row['Type'].": Symbol: ".$row['Symbol']."<br></strong>";
			?>
           	                
              <label for="Type">Type</label>
              <select id="Type" name="Type">
                <option value="<?php if($row['Type']=="buy"){echo"buy";$first="buy";}else{echo"sell";$first="sell";}?>" selected><?php if($row['Type']=="buy"){echo"buy";}else{echo"sell";}?></option>
                <option value="<?php if($first=="buy"){echo"sell";}else{echo"buy";}?>"><?php if($first=="buy"){echo"sell";}else{echo"buy";}?></option>
              </select>
              <label for="textfield">Date</label>
              <input type="date" name="Date" id="Date" value= "<?php echo $row['Date'] ?>">
              <label for="textfield3">Shares</label>
              <input type="number" name="Shares" id="Shares" value= "<?php echo $row['Shares'] ?>">
              <label for="textfield4">Price</label>
              <input type="number" step="0.01" name="Price" id="Price" value= "<?php echo $row['Price'] ?>">
              <label for="textfield5">Commission</label>
              <input type="number" step="0.01" name="Commission" id="Commission" value= "<?php echo $row['Commission'] ?>">
              <label for="textfield6">Notes</label>
              <input type="text" name="Notes" id="Notes" value= "<?php echo $row['Notes'] ?>">
              <input type="hidden" step="0.01" name="Cash Value" id="CashValue" value= "<?php echo $row['CashValue'] ?>">
              <label for="textfield7">Cash Linked</label>
              <input type="checkbox" step="0.01" name="LinkCash" id="LinkCash" value= "yes" <?php if($row['LinkCash']=="yes"){?>checked<?php } ?>>
              <input type="hidden" name="ID" id="ID" value= "<?php echo $row['ID'] ?>">
        	<?php
			}
			//Use this form for users cash pool transactions:
			if($row['Symbol']==""){
				echo"<strong>Cash: ".$row['Type']."<br></strong>";
			?>
            
              
              <label for="Type">Type</label>
              <select id="Type" name="Type">
                <option value="<?php if($row['Type']=="Deposit"){echo"Deposit";$first="Deposit";}else{echo"Withdraw";$first="Withdraw";}?>" selected><?php if($row['Type']=="Deposit"){echo"Deposit";}else{echo"Withdraw";}?></option>
                <option value="<?php if($first=="Withdraw"){echo"Deposit";}else{echo"Withdraw";}?>"><?php if($first=="Withdraw"){echo"Deposit";}else{echo"Withdraw";}?></option>
              </select>
              
              <label for="textfield">Date</label>
              <input type="date" name="Date" id="Date" value= "<?php echo $row['Date'] ?>">
              <label for="Amount">Amount</label>
              <input type="number" name="Amount" id="Amount" value= "<?php echo $row['CashValue'] ?>">
              <label for="textfield6">Notes</label>
              <input type="text" name="Notes" id="Notes" value= "<?php echo $row['Notes'] ?>">
              <input type="hidden" name="ID" id="ID" value= "<?php echo $row['ID'] ?>">

          	<?php
			}
			?>

             <input type="submit" name="submit" value="Update Entry" />
  			 <input type="submit" name="submit" value="Delete Entry" class="deleteButton">
            
             </form>
             <?php
			 echo"<br>";
			 echo"______________________________________<br>";
			}
			echo "</fieldset>\n";
			// close the database connection
			mysqli_close($con);
			?>
      
      
    </div>
    <br class="clear" />
  </div>
</div>
<div class="wrapper col6"></div>
<div class="wrapper col7">
  <div id="copyright">
    <p class="fl_left">Copyright &copy; 2011 - All Rights Reserved - <a href="#">Domain Name</a></p>
    <p class="fl_right">Template by <a href="http://www.os-templates.com/" title="Free Website Templates">OS Templates</a></p>
    <br class="clear" />
  </div>
</div>
</body>
</html>
